package com.sgcc.ln.pmos.e_ln_home.adapter;

import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.e_ln_home.bean.RetailBean;

import java.util.Random;

public class RetailQaAdapter extends BaseQuickAdapter<RetailBean.RetailListDTO, BaseViewHolder> {

    private Context mContext;

    public RetailQaAdapter(Context context) {
        super(R.layout.item_retail);
        mContext = context;
    }

    public interface OnItemClickListener {
        //条目点击
        void itemClickListener(int position, RetailBean.RetailListDTO bean);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RetailBean.RetailListDTO bean) {
        Random random = new Random();
        baseViewHolder.setText(R.id.title_txt, bean.getQuestions());
        baseViewHolder.setText(R.id.content_txt, bean.getAnswer());
        baseViewHolder.getView(R.id.back_box).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener!=null) {
                    mOnItemClickListener.itemClickListener(getItemPosition(bean),bean);
                }
            }
        });

        //生成随机数  决定背景
        int ra = random.nextInt(2);
        if (ra == 1) {
            baseViewHolder.setBackgroundResource(R.id.back_box, R.drawable.bg_gradual_lv_box);
        } else {
            baseViewHolder.setBackgroundResource(R.id.back_box, R.drawable.bg_gradual_zi_box);
        }

        //生成随机数  决定上升下降
        int raup = random.nextInt(3);
        if (raup == 0) {
            baseViewHolder.setImageResource(R.id.positionstate_img, R.mipmap.up);
        } else if (raup == 1) {
            baseViewHolder.setImageResource(R.id.positionstate_img, R.mipmap.down);
        } else {
            baseViewHolder.setImageResource(R.id.positionstate_img, R.mipmap.nomal);
        }

        //根据游标  决定是否隐藏回答
        if (getItemPosition(bean) > 3) {
            baseViewHolder.setGone(R.id.content_txt, true);
        } else {
            baseViewHolder.setGone(R.id.content_txt, false);
        }

    }

}
